<?php

declare(strict_types=1);

namespace App\Chat\Service;

use App\CustHub\Mapper\ChCustomerServiceMapper;
use App\CustHub\Model\ChRoom;

class GroupMemberService
{
    /**
     * 判断用户是否是群成员
     *
     * @param int $group_id 群ID
     * @param int $robotId  机器人ID
     * @return bool
     */
    public function isMember(int $group_id, int $robotId): bool
    {
        return ChRoom::query()
            ->where('id',$group_id)
            ->whereHas('robots',function ($query) use ($robotId){
                $query->where('robot_id',$robotId);
            })->exists();
    }


    public function getUserGroupIds(int $userId)
    {
        $customerService = di()->get(ChCustomerServiceMapper::class)->findById($userId);
        if(!empty($customerService)){
            return $customerService->rooms()->pluck('id')->toArray();
        }
        return [];
    }
}